<template>
		<Layout :class="'bg-white p-2'">
			
			<Form class="p-5" :model="param" :label-width="80">
			<Row>
			<Col span="7">
			<FormItem class="w-100" label="编号:">
				<label>{{param.accessId}}</label>
			</FormItem>
			<FormItem class="w-100" label="门店名称:">
				<label>{{name}}</label>
			</FormItem>
			<FormItem class="w-100" label="门禁型号:">
				<Input v-model="param.modelNumber"/>
			</FormItem>
			<FormItem class="w-100" label="设备ID:">
				<Input v-model="param.uid"/>
			</FormItem>
			<FormItem class="w-100" label="授权key:">
				<Input v-model="param.ukey"/>
			</FormItem>
			<FormItem class="w-100" label="序列号:">
				<Input v-model="param.sn"/>
			</FormItem>
			<FormItem class="w-100" label="状态:">
				<i-Switch v-model="param.statu" size="large">
					<span slot="open">启用</span>
					<span slot="close">停用</span>
				</i-Switch>
			</FormItem>
			<FormItem class="w-100" label="进/出门:">
				<RadioGroup :class="'w-75 m-0'" v-model="ioFlg">
					<Radio label="true">
					<span>进门 </span>
					</Radio>
					<Radio label="false">
					<span>出门</span>
					</Radio>
				</RadioGroup>
			</FormItem>
			</Col>
			</Row>
			<Row>
				<Col span="4">
					<Button class="m-5" type="primary"  @click="changeAccess()" >提交</Button>
				</Col>
				<Col span="4">
					<Button class="m-5" style="margin-left: 20px"  @click="cancel()" >取消</Button>
				</Col>
			</Row>
			</Form>
			
		</Layout>
</template>

<script>
	export default {
		data() {
			return {
				name: "name",
				storeId: "",
				ioFlg : "",
				param: {
					accessId: "",
					modelNumber: "",
					uid: "",
					ukey: "",
					sn: "",
					statu: "false",
				}
			}
		},
		methods: {
			getAccess: function() {
				this.http.get({ 
					url: "/store/access",
					param: {
						id:this.param.accessId
					}
				}).then(data => {
					this.storeId = data.storeId;
					this.name = data.name;
					this.ioFlg= data.ioFlg+'';
					this.param = data;
				});
			},
			changeAccess: function() {
				if (this.param.modelNumber.length === 0) {
					this.message.error("门禁型号必须输入");
					return;
				}
				
				if (this.param.uid.length === 0) {
					this.message.error("设备ID必须输入");
					return;
				}
				
				if (this.param.ukey.length === 0) {
					this.message.error("授权Key必须输入");
					return;
				}
				
				if (this.param.sn.length === 0) {
					this.message.error("序列号必须输入");
					return;
				}
				this.http.put({
					url: "/store/access",
					param: {
						access: this.param,
						storeId: this.storeId,
						ioFlg: this.ioFlg
					}
				}).then(() => {
					 this.message.info("修改成功");
					 this.$tabs.close();
				});
			},
			cancel: function() {
				//取消
				this.$tabs.close();
			},
		},
		beforeMount(){
			this.param.accessId = this.$route.params.accessId;
			this.getAccess();
		}
	}
</script>

<style>
</style>
